package com.desire.controller.common;

import com.desire.bean.common.ResultBean;

/**
 * @author LittleDesire
 * @description
 * @date 2022-05-07 周六 14:41
 * @since 17
 */
public class BaseController {
    private final int SUCCESS = 200;
    private final int FAIL = 0;

    protected ResultBean success(String msg) {
        return new ResultBean(SUCCESS, msg, null);
    }

    protected ResultBean success(String msg, Object data) {
        return new ResultBean(SUCCESS, msg, data);
    }

    protected ResultBean success(Object data) {
        return new ResultBean(SUCCESS, "", data);
    }

    protected ResultBean fail(String msg) {
        return new ResultBean(FAIL, msg, null);
    }

    protected ResultBean fail(String msg, Object error) {
        return new ResultBean(FAIL, msg, error);
    }

    protected ResultBean saveResult(int rs) {
        return result(rs, "保存成功", "保存失败");
    }

    protected ResultBean updateResult(int rs) {
        return result(rs, "修改成功", "修改失败");
    }

    protected ResultBean deleteResult(int rs) {
        return result(rs, "删除成功", "删除失败");
    }

    ResultBean result(int rs, String ok, String no) {
        return rs > 0 ? success(ok) : fail(no);
    }
}
